home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Universal / Interfaces / PInterfaces / Threads.p < prev    next >
Encoding:
Text File  |  1998-02-12  |  8.6 KB  |  275 lines  |  [TEXT/MPS ]

  1. {
  2.      File:        Threads.p
  3.  
  4.      Contains:    Thread Manager Interfaces.
  5.  
  6.      Version:    Technology:    Mac OS 8
  7.                  Release:    Universal Interfaces 3.1
  8.  
  9.      Copyright:    © 1991-1998 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        Please include the the file and version information (from above) with
  12.                  the problem description.  Developers belonging to one of the Apple
  13.                  developer programs can submit bug reports to:
  14.  
  15.                      devsupport@apple.com
  16.  
  17. }
  18. {$IFC UNDEFINED UsingIncludes}
  19. {$SETC UsingIncludes := 0}
  20. {$ENDC}
  21.  
  22. {$IFC NOT UsingIncludes}
  23.  UNIT Threads;
  24.  INTERFACE
  25. {$ENDC}
  26.  
  27. {$IFC UNDEFINED __THREADS__}
  28. {$SETC __THREADS__ := 1}
  29.  
  30. {$I+}
  31. {$SETC ThreadsIncludes := UsingIncludes}
  32. {$SETC UsingIncludes := 1}
  33.  
  34. {$IFC UNDEFINED __MACTYPES__}
  35. {$I MacTypes.p}
  36. {$ENDC}
  37. {$IFC UNDEFINED __MIXEDMODE__}
  38. {$I MixedMode.p}
  39. {$ENDC}
  40. {$IFC UNDEFINED __ERRORS__}
  41. {$I Errors.p}
  42. {$ENDC}
  43.  
  44.  
  45. {$PUSH}
  46. {$ALIGN MAC68K}
  47. {$LibExport+}
  48.  
  49. { Thread states }
  50.  
  51. TYPE
  52.     ThreadState                            = UInt16;
  53.  
  54. CONST
  55.     kReadyThreadState            = 0;
  56.     kStoppedThreadState            = 1;
  57.     kRunningThreadState            = 2;
  58.  
  59. { Error codes have been meoved to Errors.(pah) }
  60. { Thread environment characteristics }
  61.  
  62. TYPE
  63.     ThreadTaskRef                        = Ptr;
  64. { Thread characteristics }
  65.     ThreadStyle                            = UInt32;
  66.  
  67. CONST
  68.     kCooperativeThread            = $00000001;
  69.     kPreemptiveThread            = $00000002;
  70.  
  71. { Thread identifiers }
  72.  
  73. TYPE
  74.     ThreadID                            = UInt32;
  75.  
  76. CONST
  77.     kNoThreadID                    = 0;
  78.     kCurrentThreadID            = 1;
  79.     kApplicationThreadID        = 2;
  80.  
  81. { Options when creating a thread }
  82.  
  83. TYPE
  84.     ThreadOptions                        = UInt32;
  85.  
  86. CONST
  87.     kNewSuspend                    = $01;
  88.     kUsePremadeThread            = $02;
  89.     kCreateIfNeeded                = $04;
  90.     kFPUNotNeeded                = $08;
  91.     kExactMatchThread            = $10;
  92.  
  93. { Information supplied to the custom scheduler }
  94.  
  95. TYPE
  96.     SchedulerInfoRecPtr = ^SchedulerInfoRec;
  97.     SchedulerInfoRec = RECORD
  98.         InfoRecSize:            UInt32;
  99.         CurrentThreadID:        ThreadID;
  100.         SuggestedThreadID:        ThreadID;
  101.         InterruptedCoopThreadID: ThreadID;
  102.     END;
  103.  
  104.  
  105. {$IFC TARGET_CPU_68K AND TARGET_RT_MAC_CFM }
  106. {
  107.     The following UniversalProcPtrs are for CFM-68k compatiblity with
  108.     the implementation of the Thread Manager.
  109. }
  110.     ThreadEntryProcPtr                    = UniversalProcPtr;
  111.     ThreadSchedulerProcPtr                = UniversalProcPtr;
  112.     ThreadSwitchProcPtr                    = UniversalProcPtr;
  113.     ThreadTerminationProcPtr            = UniversalProcPtr;
  114.     DebuggerNewThreadProcPtr            = UniversalProcPtr;
  115.     DebuggerDisposeThreadProcPtr        = UniversalProcPtr;
  116.     DebuggerThreadSchedulerProcPtr        = UniversalProcPtr;
  117. {$ELSEC}
  118. {
  119.     The following ProcPtrs cannot be interchanged with UniversalProcPtrs because
  120.     of differences between 680x0 and PowerPC runtime architectures with regard to
  121.     the implementation of the Thread Manager.
  122.  }
  123. { Prototype for thread's entry (main) routine }
  124.     voidPtr                                = Ptr;
  125. {$IFC TYPED_FUNCTION_POINTERS}
  126.     ThreadEntryProcPtr = FUNCTION(threadParam: UNIV Ptr): voidPtr;
  127. {$ELSEC}
  128.     ThreadEntryProcPtr = ProcPtr;
  129. {$ENDC}
  130.  
  131. { Prototype for custom thread scheduler routine }
  132. {$IFC TYPED_FUNCTION_POINTERS}
  133.     ThreadSchedulerProcPtr = FUNCTION(schedulerInfo: SchedulerInfoRecPtr): ThreadID;
  134. {$ELSEC}
  135.     ThreadSchedulerProcPtr = ProcPtr;
  136. {$ENDC}
  137.  
  138. { Prototype for custom thread switcher routine }
  139. {$IFC TYPED_FUNCTION_POINTERS}
  140.     ThreadSwitchProcPtr = PROCEDURE(threadBeingSwitched: ThreadID; switchProcParam: UNIV Ptr);
  141. {$ELSEC}
  142.     ThreadSwitchProcPtr = ProcPtr;
  143. {$ENDC}
  144.  
  145. { Prototype for thread termination notification routine }
  146. {$IFC TYPED_FUNCTION_POINTERS}
  147.     ThreadTerminationProcPtr = PROCEDURE(threadTerminated: ThreadID; terminationProcParam: UNIV Ptr);
  148. {$ELSEC}
  149.     ThreadTerminationProcPtr = ProcPtr;
  150. {$ENDC}
  151.  
  152. { Prototype for debugger NewThread notification }
  153. {$IFC TYPED_FUNCTION_POINTERS}
  154.     DebuggerNewThreadProcPtr = PROCEDURE(threadCreated: ThreadID);
  155. {$ELSEC}
  156.     DebuggerNewThreadProcPtr = ProcPtr;
  157. {$ENDC}
  158.  
  159. { Prototype for debugger DisposeThread notification }
  160. {$IFC TYPED_FUNCTION_POINTERS}
  161.     DebuggerDisposeThreadProcPtr = PROCEDURE(threadDeleted: ThreadID);
  162. {$ELSEC}
  163.     DebuggerDisposeThreadProcPtr = ProcPtr;
  164. {$ENDC}
  165.  
  166. { Prototype for debugger schedule notification }
  167. {$IFC TYPED_FUNCTION_POINTERS}
  168.     DebuggerThreadSchedulerProcPtr = FUNCTION(schedulerInfo: SchedulerInfoRecPtr): ThreadID;
  169. {$ELSEC}
  170.     DebuggerThreadSchedulerProcPtr = ProcPtr;
  171. {$ENDC}
  172.  
  173. {$ENDC}
  174.  
  175.  
  176. { Thread Manager routines }
  177. FUNCTION CreateThreadPool(threadStyle: ThreadStyle; numToCreate: INTEGER; stackSize: Size): OSErr;
  178.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  179.     INLINE $303C, $0501, $ABF2;
  180.     {$ENDC}
  181. FUNCTION GetFreeThreadCount(threadStyle: ThreadStyle; VAR freeCount: INTEGER): OSErr;
  182.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  183.     INLINE $303C, $0402, $ABF2;
  184.     {$ENDC}
  185. FUNCTION GetSpecificFreeThreadCount(threadStyle: ThreadStyle; stackSize: Size; VAR freeCount: INTEGER): OSErr;
  186.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  187.     INLINE $303C, $0615, $ABF2;
  188.     {$ENDC}
  189. FUNCTION GetDefaultThreadStackSize(threadStyle: ThreadStyle; VAR stackSize: Size): OSErr;
  190.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  191.     INLINE $303C, $0413, $ABF2;
  192.     {$ENDC}
  193. FUNCTION ThreadCurrentStackSpace(thread: ThreadID; VAR freeStack: UInt32): OSErr;
  194.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  195.     INLINE $303C, $0414, $ABF2;
  196.     {$ENDC}
  197. FUNCTION NewThread(threadStyle: ThreadStyle; threadEntry: ThreadEntryProcPtr; threadParam: UNIV Ptr; stackSize: Size; options: ThreadOptions; VAR threadResult: UNIV Ptr; VAR threadMade: ThreadID): OSErr;
  198.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  199.     INLINE $303C, $0E03, $ABF2;
  200.     {$ENDC}
  201. FUNCTION DisposeThread(threadToDump: ThreadID; threadResult: UNIV Ptr; recycleThread: BOOLEAN): OSErr;
  202.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  203.     INLINE $303C, $0504, $ABF2;
  204.     {$ENDC}
  205. FUNCTION YieldToThread(suggestedThread: ThreadID): OSErr;
  206.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  207.     INLINE $303C, $0205, $ABF2;
  208.     {$ENDC}
  209. FUNCTION YieldToAnyThread: OSErr;
  210.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  211.     INLINE $42A7, $303C, $0205, $ABF2;
  212.     {$ENDC}
  213. FUNCTION GetCurrentThread(VAR currentThreadID: ThreadID): OSErr;
  214.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  215.     INLINE $303C, $0206, $ABF2;
  216.     {$ENDC}
  217. FUNCTION GetThreadState(threadToGet: ThreadID; VAR threadState: ThreadState): OSErr;
  218.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  219.     INLINE $303C, $0407, $ABF2;
  220.     {$ENDC}
  221. FUNCTION SetThreadState(threadToSet: ThreadID; newState: ThreadState; suggestedThread: ThreadID): OSErr;
  222.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  223.     INLINE $303C, $0508, $ABF2;
  224.     {$ENDC}
  225. FUNCTION SetThreadStateEndCritical(threadToSet: ThreadID; newState: ThreadState; suggestedThread: ThreadID): OSErr;
  226.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  227.     INLINE $303C, $0512, $ABF2;
  228.     {$ENDC}
  229. FUNCTION SetThreadScheduler(threadScheduler: ThreadSchedulerProcPtr): OSErr;
  230.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  231.     INLINE $303C, $0209, $ABF2;
  232.     {$ENDC}
  233. FUNCTION SetThreadSwitcher(thread: ThreadID; threadSwitcher: ThreadSwitchProcPtr; switchProcParam: UNIV Ptr; inOrOut: BOOLEAN): OSErr;
  234.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  235.     INLINE $303C, $070A, $ABF2;
  236.     {$ENDC}
  237. FUNCTION SetThreadTerminator(thread: ThreadID; threadTerminator: ThreadTerminationProcPtr; terminationProcParam: UNIV Ptr): OSErr;
  238.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  239.     INLINE $303C, $0611, $ABF2;
  240.     {$ENDC}
  241. FUNCTION ThreadBeginCritical: OSErr;
  242.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  243.     INLINE $303C, $000B, $ABF2;
  244.     {$ENDC}
  245. FUNCTION ThreadEndCritical: OSErr;
  246.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  247.     INLINE $303C, $000C, $ABF2;
  248.     {$ENDC}
  249. FUNCTION SetDebuggerNotificationProcs(notifyNewThread: DebuggerNewThreadProcPtr; notifyDisposeThread: DebuggerDisposeThreadProcPtr; notifyThreadScheduler: DebuggerThreadSchedulerProcPtr): OSErr;
  250.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  251.     INLINE $303C, $060D, $ABF2;
  252.     {$ENDC}
  253. FUNCTION GetThreadCurrentTaskRef(VAR threadTRef: ThreadTaskRef): OSErr;
  254.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  255.     INLINE $303C, $020E, $ABF2;
  256.     {$ENDC}
  257. FUNCTION GetThreadStateGivenTaskRef(threadTRef: ThreadTaskRef; threadToGet: ThreadID; VAR threadState: ThreadState): OSErr;
  258.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  259.     INLINE $303C, $060F, $ABF2;
  260.     {$ENDC}
  261. FUNCTION SetThreadReadyGivenTaskRef(threadTRef: ThreadTaskRef; threadToSet: ThreadID): OSErr;
  262.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  263.     INLINE $303C, $0410, $ABF2;
  264.     {$ENDC}
  265. {$ALIGN RESET}
  266. {$POP}
  267.  
  268. {$SETC UsingIncludes := ThreadsIncludes}
  269.  
  270. {$ENDC} {__THREADS__}
  271.  
  272. {$IFC NOT UsingIncludes}
  273.  END.
  274. {$ENDC}
  275.